package com.example.demo.commen;

public class AppResult<T> {

      int code;

      String message;

      T data;

      public static <T>AppResult<T> success(T data){
            AppResult result = new AppResult();
            result.setCode(ResultCode.SUCCESS.getCode());
            result.setMessage("成功");
            result.setData(data);
            return result;
      }

      public static AppResult success(){
            AppResult result = new AppResult();

            result.setCode(ResultCode.SUCCESS.getCode());
            result.setMessage("操作成功");
            result.setData(null);
            return  result;
      }

      public static<T> AppResult<T> failed(String message){
            AppResult result = new AppResult();
            result.setCode(ResultCode.FAILED.getCode());
            result.setMessage(message);
            result.setData(null);
            return result;
      }

      public static<T> AppResult<T> failed(){
            AppResult result = new AppResult();
            result.setCode(ResultCode.FAILED.getCode());
            result.setMessage("操作失败");
            result.setData(null);
            return result;
      }


      public int getCode() {
            return code;
      }

      public void setCode(int code) {
            this.code = code;
      }

      public String getMessage() {
            return message;
      }

      public void setMessage(String message) {
            this.message = message;
      }

      public T getData() {
            return data;
      }

      public void setData(T data) {
            this.data = data;
      }
}
